/*
 * @lc app=leetcode.cn id=1678 lang=typescript
 *
 * [1678] 设计 Goal 解析器
 */

// @lc code=start
function interpret(command: string): string {
    const stack: string[] = [];
    for (let i = 0; i < command.length; i++) {
        const element = command[i];
        if (element === ")") {
            let final = "";
            while (stack[stack.length - 1] !== "(") {
                final = stack.pop() + final;
            }
            final = stack.pop() + final;

            if (final === "(al") {
                stack.push("al");
            } else {
                stack.push("o");
            }
        } else {
            stack.push(element);
        }
    }
    return stack.join("");
}
// @lc code=end
